package com.mypg;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class InfoHelper {
    private int info_id;
    private String info_title;
    private String info_content;
    private String info_time;
    private String info_class;

    public static InfoHelper changeInfoToInfoHelper(Info info){
        InfoHelper infoHelper=new InfoHelper();
        infoHelper.setInfo_id(info.getInfo_id());
        infoHelper.setInfo_title(info.getInfo_title());
        infoHelper.setInfo_content(info.getInfo_content());
        infoHelper.setInfo_class(info.getInfo_class());

        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String tool=String.valueOf(info.getInfo_time());
//        infoHelper.setInfo_time(tool.substring(0,tool.length()-5));
        infoHelper.setInfo_time(df.format(info.getInfo_time().getTime()));
        return infoHelper;
    }

    public static List<InfoHelper> changeInfolistToInfoHelperlist(List<Info> infoList){
        List<InfoHelper> infoHelperList=new ArrayList<>();
        for(int i=0;i<infoList.size();i++){
            infoHelperList.add(InfoHelper.changeInfoToInfoHelper(infoList.get(i)));
        }
        return infoHelperList;
    }


    public InfoHelper(){}
    public InfoHelper(int info_id, String info_title, String info_content, String info_time, String info_class) {
        this.info_id = info_id;
        this.info_title = info_title;
        this.info_content = info_content;
        this.info_time = info_time;
        this.info_class = info_class;
    }

    public int getInfo_id() {
        return info_id;
    }

    public void setInfo_id(int info_id) {
        this.info_id = info_id;
    }

    public String getInfo_title() {
        return info_title;
    }

    public void setInfo_title(String info_title) {
        this.info_title = info_title;
    }

    public String getInfo_content() {
        return info_content;
    }

    public void setInfo_content(String info_content) {
        this.info_content = info_content;
    }

    public String getInfo_time() {
        return info_time;
    }

    public void setInfo_time(String info_time) {
        this.info_time = info_time;
    }

    public String getInfo_class() {
        return info_class;
    }

    public void setInfo_class(String info_class) {
        this.info_class = info_class;
    }

    @Override
    public String toString() {
        return "InfoHelper{" +
                "info_id=" + info_id +
                ", info_title='" + info_title + '\'' +
                ", info_content='" + info_content + '\'' +
                ", info_time='" + info_time + '\'' +
                ", info_class='" + info_class + '\'' +
                '}';
    }
}
